package zozopo.attendance;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.attendance.operations.LeaveOS;
import zozopo.attendance.operations.LeaveTB;
import zozopo.attendance.operations.OperatorAttendanceOS;
import zozopo.attendance.operations.OperatorAttendanceTB;
import zozopo.background.operator.operations.OperatorTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ManageLeaveAction  extends ActionSupport implements Action,SessionAware{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	//分页参数
	private int beginPageNum = 0;
	private int pageSize = 20;
	private int rowNum = 0;
	

	//传出参数
	private List<LeaveTB> leaveList;
	
	private OperatorAttendanceTB operatorOfAttendance;
	private OperatorTB operator;

	
	
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
	
		return SUCCESS;
		
	}

	public void validate() {
		//权限处理
	
		operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		//用户权限
		
		OperatorAttendanceOS operatorOfAttendanceOS = new OperatorAttendanceOS();
		LeaveOS leaveOS = new LeaveOS(operatorOfAttendanceOS.getConn());
		if(!operatorOfAttendanceOS.isExist(operator.getId_operator())){
			operatorOfAttendanceOS.releaseConnection();
			addFieldError("errormessage","用户未加入考勤系统无法请假!请联系管理人员.!!");
			return ; 
		}
		operatorOfAttendance = operatorOfAttendanceOS.getInfoByOperatorid(operator.getId_operator());
		

		leaveList = leaveOS.selectAll(beginPageNum, pageSize);
		rowNum = leaveOS.getRowNum();
		
		operatorOfAttendanceOS.releaseConnection();
	}
	public OperatorAttendanceTB getOperatorOfAttendance() {
		return operatorOfAttendance;
	}
	public void setOperatorOfAttendance(OperatorAttendanceTB operatorOfAttendance) {
		this.operatorOfAttendance = operatorOfAttendance;
	}
	public OperatorTB getOperator() {
		return operator;
	}
	public void setOperator(OperatorTB operator) {
		this.operator = operator;
	}
	
	
	public List<LeaveTB> getLeaveList() {
		return leaveList;
	}
	public void setLeaveList(List<LeaveTB> leaveList) {
		this.leaveList = leaveList;
	}
	public int getBeginPageNum() {
		return beginPageNum;
	}
	public void setBeginPageNum(int beginPageNum) {
		this.beginPageNum = beginPageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getRowNum() {
		return rowNum;
	}
	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}

}
